#include "pch.h"
#include "Stock.h"


void drawSegmentWithHLC(int dataLen, float* pfOUT, float* high, float* low, float* close) {
	IChanLun* chanlun = new ChanLunWithHLC();
	chanlun->drawSegment(dataLen, pfOUT, high, low, close);
	delete chanlun;
}

void drawCenterHighWithHLC(int dataLen, float* pfOUT, float* high, float* low, float* close) {
	IChanLun* chanlun = new ChanLunWithHLC();
	chanlun->drawCenterHigh(dataLen, pfOUT, high, low, close);
	delete chanlun;
}

void drawCenterLowWithHLC(int dataLen, float* pfOUT, float* high, float* low, float* close) {
	IChanLun* chanlun = new ChanLunWithHLC();
	chanlun->drawCenterLow(dataLen, pfOUT, high, low, close);
	delete chanlun;
}

void drawSegmentWithC(int dataLen, float* pfOUT, float* high, float* low, float* close) {
	IChanLun* chanlun = new ChanLunWithC();
	chanlun->drawSegment(dataLen, pfOUT, high, low, close);
	delete chanlun;
}

void drawCenterHighWithC(int dataLen, float* pfOUT, float* high, float* low, float* close) {
	IChanLun* chanlun = new ChanLunWithC();
	chanlun->drawCenterHigh(dataLen, pfOUT, high, low, close);
	delete chanlun;
}

void drawCenterLowWithC(int dataLen, float* pfOUT, float* high, float* low, float* close) {
	IChanLun* chanlun = new ChanLunWithC();
	chanlun->drawCenterLow(dataLen, pfOUT, high, low, close);
	delete chanlun;
}

void drawBearTrap(int dataLen, float* pfOUT, float* high, float* low, float* close) {
	vector<KLine*>* kLines = initKLines(dataLen, high, low, close);
	for (int i = dataLen-1; i > 0; i--) {
		if (isBearTrap(kLines, i)) {
			pfOUT[i] = 1;
		}
	}
	clearKLines(kLines);
}

void drawTurn(int dataLen, float* pfOUT, float* high, float* low, float* close) {
	float* rsi6 = RSI(dataLen, close, 6);
	float* ema5 = EMA(dataLen, close, 5);
	float* ema10 = EMA(dataLen, close, 10);
	MACD* macd = calculateMACD2(dataLen, ema5, ema10, 12, 26, 9);

	bool* fallTurn = isFallEnd(dataLen, high, low, close, rsi6, macd);
	bool* riseTurn = isRiseEnd(dataLen, high, low, close, rsi6, macd);

	for (int i = 0; i < dataLen; i++) {
		if (fallTurn[i]) {
			pfOUT[i] = 1;
		}
		else if (riseTurn[i]) {
			pfOUT[i] = -1;
		}
		else {
			pfOUT[i] = 0;
		}
	}
}